﻿using Api.Application.Command.UserRole;
using Api.DTO;
using ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers
{
    /// <summary>
    /// 角色用户中间控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserRoleController : ControllerBase
    {
        private readonly IMediator mediator;

        public UserRoleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 分配
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddUserRole(AddUserRoleCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 根据角色id反填对应的角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<UserRoleDTO>>> GetUserRole([FromQuery]GetUserRoleCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除反填过来的用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<int>> DelUserRole([FromQuery] DelUserRoleCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
